import 'package:flutter/material.dart';
import 'package:flutterapp2/building/buildinfo.dart';

class BuildingWidget extends StatefulWidget {
  final BuildInfo data;
  final ValueChanged<int> listener;

  const BuildingWidget(this.data, this.listener, {Key key})
      : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _BuildingState();
  }
}

class _BuildingState extends State<BuildingWidget> {
  BuildInfo data;

  @override
  void initState() {
    super.initState();
    data = widget.data;
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        data.isSelected = !data.isSelected;
        widget.listener(data.isSelected ? 1 : -1);
        setState(() {});
      },
      child: Container(
        decoration: BoxDecoration(
          color: Color(0xFFF8F8F8),
          borderRadius: BorderRadius.circular(2),
        ),
        child: Stack(
          alignment: Alignment.center,
          children: <Widget>[
            Text(data.name, style: TextStyle(color: Color(0xFF222222))),
            Align(
              alignment: Alignment.topRight,
              child: Image.asset(
                data.isSelected
                    ? 'assets/images/ic_building_checked.png'
                    : 'assets/images/ic_building_normal.png',
                width: 20,
                height: 20,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
